#include "searcher.hpp"
#include "cpp-httplib/httplib.h"

const std::string root_path = "./wwwroot";
const std::string input = "data/raw_html/raw.txt";
int main()
{
  ns_searcher::Searcher search;
  search.InitSearcher(input);

  httplib::Server server;
  server.set_base_dir(root_path.c_str());
  server.Get("/s",[&search](const httplib::Request& req,httplib::Response& rsp){
      if(!req.has_param("word"))
      {
        rsp.set_content("搜索内容不能为空！","text/plain; charset=utf-8");
        return; 
      }
      std::string word = req.get_param_value("word");
      LOG(NORMAL,"用户在搜索："+ word);
      std::string json_string;
      search.Search(word,&json_string);
      rsp.set_content(json_string,"application/json");
      //rsp.set_content("hello world","text/plain: charset=utf-8");
      });
  server.listen("0.0.0.0",8081);
  return 0;
}
